<?php
namespace Framework\Library\Validator;

use Phalcon\Validation;
use Phalcon\Validation\Message;
use Framework\Library\Tool;

class AudioValidator extends BinaryValidator
{
    public function validate(Validation $validation, $attribute)
    {
        if (parent::validate($validation, $attribute) == false) {
            return false;
        }

        $supportedAudioMimeTypes = [
            'audio/mp4',
            'video/mp4',
            'video/3gpp',
            'audio/x-hx-aac-adts',
            'audio/aac',
        ];

        $mimeType = Tool::getMimeType($_FILES[$attribute]['tmp_name']);
        if (in_array($mimeType, $supportedAudioMimeTypes)) {
            return true;
        }

        $validation->appendMessage(new Message('Unsupported audio type', $attribute, 'Audio'));

        return false;
    }
}
